using System.Collections;
using System.Collections.Generic;
using System.Threading;
using DG.Tweening;
using TMPro;
using UnityEngine;

public class UIManager : MonoBehaviour
{
    public static UIManager Instance { get; private set; }
    public TextMeshProUGUI sunSumText;
    public ProgressPanel progressPanel;
    int zombieDiedCount = 0;//死亡僵尸数量
    public GameObject cardPanel;//选项卡
    public Transform pickUpPos;//阳光拾取位置
    public SpriteRenderer spriteRenderer;//背景图片
    
    private void Awake()
    {
        Instance = this;
    }

    private void Start()
    {
        //配置背景
        spriteRenderer.sprite = LevelItemData.Instance.item.bgSprite; 

        Init();
        zombieDiedCount = 0;
        InitProgressPanel();
        
        cardPanel.SetActive(true);
        cardPanel.transform.DOMove(cardPanel.transform.position, 1f).From(new Vector2(0, 0));
    }

    public void Init()
    {
        sunSumText.text = GameManager.Instance.sunSum.ToString();
    }

    //初始化进度条
    public void InitProgressPanel()
    {
        // 初始化进度为0
        progressPanel.SetPercent(0);

        int count = GameManager.Instance.listData.Count;
        string progressId = GameManager.Instance.listData[0]["progressId"];
        // 遍历数据列表,设置旗帜的位置
        for (int i = 0; i < count; i++)
        {
            // 获取当前字典数据
            Dictionary<string, string> dic = GameManager.Instance.listData[i];
            if (progressId != dic["progressId"])
            {
                progressPanel.SetFlagPercent((float)i / count);
            }
            progressId = dic["progressId"];
        }
    }

    //更新进度
    public void UpdateProgressPanel()
    {
        zombieDiedCount++;
        progressPanel.SetPercent((float)zombieDiedCount / GameManager.Instance.listData.Count);
    }
}
